package com.gift.recommendation.modules.user.controller;

import com.gift.recommendation.Base.BaseResponse;
import com.gift.recommendation.Base.PageData;
import com.gift.recommendation.modules.user.biz.ShoppingCartBiz;
import com.gift.recommendation.modules.user.dto.ShoppingCartReq;
import com.gift.recommendation.modules.user.dto.ShoppingCartListReq;
import com.gift.recommendation.modules.user.dto.ShoppingCartRsp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zzh <2658137258@qq.com>
 * @date 2023/4/1
 */
@RestController
@RequestMapping("/gift/shopping-cart")
@Api(tags = "购物车管理")
@Validated
public class ShoppingCartController {

    @Autowired
    private ShoppingCartBiz shoppingCartBiz;

    @ApiOperation(value = "用户填写商品进购物车")
    @RequestMapping(path = "/add",method = RequestMethod.POST)
    public BaseResponse addGoods(@RequestBody ShoppingCartReq req){
        shoppingCartBiz.addGoods(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "用户修改购物车商品数量")
    @RequestMapping(path = "/change",method = RequestMethod.POST)
    public BaseResponse changeGoods(@RequestBody ShoppingCartReq req){
        shoppingCartBiz.changeGoods(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "用户删除购物车物品")
    @RequestMapping(path = "/delete",method = RequestMethod.POST)
    public BaseResponse deleteGoods(@RequestBody ShoppingCartReq req){
        shoppingCartBiz.deleteGoods(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "用户获取购物车物品")
    @RequestMapping(path = "/get",method = RequestMethod.POST)
    public BaseResponse<PageData<ShoppingCartRsp>> getGoodsList(@RequestBody ShoppingCartListReq req){
        PageData<ShoppingCartRsp> result = shoppingCartBiz.getGoodsList(req);
        return BaseResponse.success(result);
    };
}
